<template>
  <a-card :bordered="false">

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="tid"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="configSlot" slot-scope="text,record">
          <a @click="showConfigInfo(record)">配置</a>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>


          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a @click="testConn(record)">测试连接</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.tid)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <collect-source-modal ref="modalForm" @ok="modalFormOk"></collect-source-modal>
    <config-modal ref="configForm" @ok="modalFormOk"></config-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin.js'
  import CollectSourceModal from './modules/CollectSourceModal'
  import ConfigModal from './modules/CollectSourceConfig'

  export default {
    name: 'CollectSourceList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      CollectSourceModal,
      ConfigModal
    },
    data () {
      return {
        description: '数据源表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'数据源类型',
            align:"center",
            dataIndex: 'sourceType'
          },
          {
            title:'数据源名称',
            align:"center",
            dataIndex: 'sourceName'
          },
          {
            title: '数据源配置详情',
            dataIndex: 'configSlot',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'configSlot' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          page: "/dcloud-platform/api/collectSource/v1/page",
          delete: "/dcloud-platform/api/collectSource/v1/delete",
          deleteBatch: "/dcloud-platform/api/collectSource/v1/deleteBatch",
          exportXlsUrl: "/dcloud-platform/api/collectSource/v1/exportXls",
          importExcelUrl: "com.dcloud.manage/collectSource/v1/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'int',value:'tid',text:'主键',dictCode:''})
        fieldList.push({type:'int',value:'sourceDefTid',text:'数据源定义id',dictCode:''})
        fieldList.push({type:'string',value:'sourceName',text:'数据源名称',dictCode:''})
        this.superFieldList = fieldList
      },
      showConfigInfo(record){
        this.$refs.configForm.edit(record)
        this.$refs.configForm.title = '配置'
        this.$refs.configForm.disableSubmit = false
      },
      testConn(record){
        this.$refs.configForm.testConn(record)
      }

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>